#include <modules\audio\fmod\fmod_sound.h>

namespace DelGE
{
	namespace Modules
	{
		namespace Audio
		{
			FModSound::FModSound(string sFilepath, FMOD::System *pFModSystemHandle)
			{
				this->pSystemHandle = pFModSystemHandle;
				if (this->pSystemHandle->createSound(sFilepath.c_str(), FMOD_DEFAULT, NULL, &this->pSoundHandle) != FMOD_OK)
					throw("Could not load sound file \"" + sFilepath + "\"");

				this->pSoundHandle->getLength(&this->uiLengthMS, FMOD_TIMEUNIT_MS);
			}

			FModSound::~FModSound()
			{
				this->pSoundHandle->release();
			}

			void FModSound::Play()
			{
				FMOD::Channel *pTemporyChannel;
				this->pSystemHandle->playSound(FMOD_CHANNEL_FREE, this->pSoundHandle, false, &pTemporyChannel);
				pTemporyChannel->setVolume(this->fVolume);
			}

			void FModSound::SetVolume(float fVolume)
			{
				this->fVolume = fVolume;
			}

			FMOD::System* FModSound::GetFModSystemHandle()
			{
				return this->pSystemHandle;
			}

			FMOD::Sound* FModSound::GetFModSoundHandle()
			{
				return this->pSoundHandle;
			}
		}
	}
}